package com.ruoyi.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.user.domain.TbUserVerification;
import com.ruoyi.user.service.ITbUserVerificationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 认证审核Controller
 * 
 * @author ruoyi
 * @date 2025-07-30
 */
@RestController
@RequestMapping("/verification/verification")
public class TbUserVerificationController extends BaseController
{
    @Autowired
    private ITbUserVerificationService tbUserVerificationService;

    /**
     * 查询认证审核列表
     */
    @PreAuthorize("@ss.hasPermi('verification:verification:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbUserVerification tbUserVerification)
    {
        startPage();
        List<TbUserVerification> list = tbUserVerificationService.selectTbUserVerificationList(tbUserVerification);
        return getDataTable(list);
    }

    /**
     * 导出认证审核列表
     */
    @PreAuthorize("@ss.hasPermi('verification:verification:export')")
    @Log(title = "认证审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbUserVerification tbUserVerification)
    {
        List<TbUserVerification> list = tbUserVerificationService.selectTbUserVerificationList(tbUserVerification);
        ExcelUtil<TbUserVerification> util = new ExcelUtil<TbUserVerification>(TbUserVerification.class);
        util.exportExcel(response, list, "认证审核数据");
    }

    /**
     * 获取认证审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('verification:verification:query')")
    @GetMapping(value = "/{verificationId}")
    public AjaxResult getInfo(@PathVariable("verificationId") Long verificationId)
    {
        return success(tbUserVerificationService.selectTbUserVerificationByVerificationId(verificationId));
    }

    /**
     * 新增认证审核
     */
    @PreAuthorize("@ss.hasPermi('verification:verification:add')")
    @Log(title = "认证审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbUserVerification tbUserVerification)
    {
        return toAjax(tbUserVerificationService.insertTbUserVerification(tbUserVerification));
    }

    /**
     * 修改认证审核
     */
    @PreAuthorize("@ss.hasPermi('verification:verification:edit')")
    @Log(title = "认证审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbUserVerification tbUserVerification)
    {
        return toAjax(tbUserVerificationService.updateTbUserVerification(tbUserVerification));
    }

    /**
     * 删除认证审核
     */
    @PreAuthorize("@ss.hasPermi('verification:verification:remove')")
    @Log(title = "认证审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{verificationIds}")
    public AjaxResult remove(@PathVariable Long[] verificationIds)
    {
        return toAjax(tbUserVerificationService.deleteTbUserVerificationByVerificationIds(verificationIds));
    }

    /**
     * 通过认证审核
     */
    @PreAuthorize("@ss.hasPermi('verification:verification:edit')")
    @Log(title = "认证审核", businessType = BusinessType.UPDATE)
    @PutMapping("/approve/{verificationId}")
    public AjaxResult approve(@PathVariable Long verificationId)
    {
        return toAjax(tbUserVerificationService.approveVerification(verificationId));
    }

    /**
     * 驳回认证审核
     */
    @PreAuthorize("@ss.hasPermi('verification:verification:edit')")
    @Log(title = "认证审核", businessType = BusinessType.UPDATE)
    @PutMapping("/reject")
    public AjaxResult reject(@RequestBody TbUserVerification tbUserVerification)
    {
        return toAjax(tbUserVerificationService.rejectVerification(tbUserVerification.getVerificationId(), tbUserVerification.getRejectReason()));
    }
}